package GUI;

import 试题和试卷.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class randomOrganizeWindow extends JFrame {
    public static JPanel mainPanel;
    public static ArrayList<selectionQuestion> selectionQuestions;
    public static ArrayList<definitionQuestion>definitionQuestions;
    public static ArrayList<subjectiveQuestion>subjectiveQuestions;
    public static ArrayList<fillingblankQuestion>fillingblankQuestions;
    public static ArrayList<question>questions;
    public JButton detailButton,finishButton,confirmButton;
    public JLabel timeLabel,numLabel, difficultyLabel,label;
    JTextArea time;
    public static int max,min;
    static randomOrganizeWindow randomOrganize;

    public randomOrganizeWindow(){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        selectionQuestions= new ArrayList<>();
        definitionQuestions= new ArrayList<>();
        subjectiveQuestions= new ArrayList<>();
        fillingblankQuestions= new ArrayList<>();
        questions=new ArrayList<>();
        int selectionNum=0,definitionNum = 0,fillingBlankNum= 0,subjectiveNum= 0;
        selectionNum=selectionQuestions.size();
        definitionNum=definitionQuestions.size();
        fillingBlankNum=fillingblankQuestions.size();
        subjectiveNum=subjectiveQuestions.size();

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton chooseSelection = new JButton("添加试题");
        JButton chooseDefinition = new JButton("添加试题");
        JButton chooseFillingBlank = new JButton("添加试题");
        JButton chooseSubjective = new JButton("添加试题");
        /*JButton*/ detailButton = new JButton("查看试题");
        /*JButton */finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");

        timeLabel = new JLabel("时间(min)：");
        time = new JTextArea(1,5);





        chooseSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        chooseDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        chooseFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        chooseSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        chooseSelection.setBounds(100,30,100,30);
        chooseDefinition.setBounds(100,90,100,30);
        chooseFillingBlank.setBounds(100,150,100,30);
        chooseSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,300,90,30);
        finishButton.setBounds(210,300,90,30);
        confirmButton.setBounds(210,300,90,30);
        timeLabel.setBounds(20,260,70,20);
        time.setBounds(100,260,200,30);


        chooseSelection.addActionListener(new chooseSelectionListener());
        chooseDefinition.addActionListener(new chooseDefinitionListener());
        chooseFillingBlank.addActionListener(new chooseFillingBlankListener());
        chooseSubjective.addActionListener(new chooseSubjectiveListener());
        //detailButton.addActionListener(new checkListener());
        //finishButton.addActionListener(new finishListener());

        if(selectionNum>0){
            chooseSelection.setEnabled(false);
        }
        if(definitionNum>0){
            chooseDefinition.setEnabled(false);
        }
        if(fillingBlankNum>0){
            chooseFillingBlank.setEnabled(false);
        }
        if(subjectiveNum>0){
            chooseSubjective.setEnabled(false);
        }



        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(chooseSelection);
        mainPanel.add(chooseDefinition);
        mainPanel.add(chooseFillingBlank);
        mainPanel.add(chooseSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);






        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
        if(!chooseSelection.isEnabled()&&!chooseDefinition.isEnabled()&&!chooseFillingBlank.isEnabled()&&!chooseSubjective.isEnabled()){
            mainPanel.add(timeLabel);
            mainPanel.add(time);
            detailButton.setBounds(60,330,90,30);
            finishButton.setBounds(210,330,90,30);
            this.setSize(370,440);
        }
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public class chooseSelectionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(1);
            randomOrganizeWindow.this.dispose();

        }
    }
    public class chooseDefinitionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(2);
            randomOrganizeWindow.this.dispose();

        }
    }
    public class chooseFillingBlankListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(3);
            randomOrganizeWindow.this.dispose();

        }
    }
    public class chooseSubjectiveListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(4);
            randomOrganizeWindow.this.dispose();

        }
    }
}
